'use strict';

module.exports = app => {
  const { STRING, INTEGER, TEXT, DATE } = app.Sequelize;

  const InterviewExperience = app.model.define('interview_experience', {
    experience_id: {
      type: INTEGER,
      primaryKey: true,
      autoIncrement: true,
      comment: '经验编号',
    },
    company_id: {
      type: INTEGER,
      allowNull: true,
      comment: '企业编号',
    },
    company_name: {
      type: STRING(100),
      allowNull: false,
      comment: '面试公司',
    },
    position: {
      type: STRING(100),
      allowNull: false,
      comment: '面试岗位',
    },
    user_id: {
      type: INTEGER,
      allowNull: false,
      defaultValue: 1,
      comment: '用户编号',
    },
    is_anonymous: {
      type: INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '是否匿名 0-否 1-是',
    },
    experience_content: {
      type: TEXT,
      allowNull: false,
      comment: '面试经验内容',
    },
    interview_questions: {
      type: TEXT,
      allowNull: true,
      comment: '面试题目',
    },
    status: {
      type: INTEGER,
      allowNull: false,
      defaultValue: 1,
      comment: '状态 1-正常 0-隐藏',
    },
    created_at: {
      type: DATE,
      allowNull: false,
      comment: '创建时间',
    },
  }, {
    tableName: 'interview_experience',
    timestamps: true,
    createdAt: 'created_at',
    updatedAt: false,
    comment: '面试经验分享表',
  });

  // 关联关系
  InterviewExperience.associate = function() {
    // 一个经验可以有多个评论
    app.model.InterviewExperience.hasMany(app.model.ExperienceComment, {
      foreignKey: 'experience_id',
      as: 'comments',
    });
  };

  return InterviewExperience;
};
